﻿using System;
using System.IO;
using System.Xml;

namespace DBConnection
{
    public static class FileUtility
    {
        public static void ReadConfig(String filePath, out String source, out String user, 
            out String password, out String db, out String securityType)
        {
            XmlDocument configFile = new XmlDocument();
            configFile.Load(filePath);

            source = configFile.GetElementsByTagName("SERVER")[0].InnerText;
            user = configFile.GetElementsByTagName("USERNAME")[0].InnerText;
            password = configFile.GetElementsByTagName("PASSWORD")[0].InnerText;
            db = configFile.GetElementsByTagName("DBNAME")[0].InnerText;
            securityType = configFile.GetElementsByTagName("SECURITY")[0].InnerText;
        }

        public static bool WriteLine(String filepath, String message)
        {
            StreamWriter targetFile = new StreamWriter(filepath, true, System.Text.Encoding.UTF8);
            targetFile.WriteLine(message);
            targetFile.Close();
            return true;
        }

        public static bool Write(String filepath, String message)
        {
            StreamWriter targetFile = new StreamWriter(filepath, true, System.Text.Encoding.UTF8);
            targetFile.Write(message);
            targetFile.Close();
            return true;
        }
    }
}
